import { metaphone } from './metaphone.js'

function undefinedTest() {
    let result;
    const str = undefined;
    const startTime = Date.now();
    for (let index = 0; index < 3000000; index++) {
        result = metaphone(str);
    }
    const endTime = Date.now();
    if (result != '') {
        throw new Error('Metaphone_Metaphone_Func_0100 error');
    }
    print(`Metaphone_Metaphone_Func_0100: ${endTime - startTime} ms`);
}

function nullTest() {
    let result;
    const str = null;
    const startTime = Date.now();
    for (let index = 0; index < 3000000; index++) {
        result = metaphone(str);
    }
    let endTime = Date.now();
    if (result != '') {
        throw new Error('Metaphone_Metaphone_Func_0200 error');
    }
    print(`Metaphone_Metaphone_Func_0200: ${endTime - startTime} ms`);
}

function strTestOne() {
    let result;
    const str = '';
    const startTime = Date.now();
    for (let index = 0; index < 3000000; index++) {
        result = metaphone(str);
    }
    let endTime = Date.now();
    if (result != '') {
        throw new Error('Metaphone_Metaphone_Func_0300 error');
    }
    print(`Metaphone_Metaphone_Func_0300: ${endTime - startTime} ms`);
}

function strTestTwo() {
    let result;
    const str = '0 1 2';
    const startTime = Date.now();
    for (let index = 0; index < 3000000; index++) {
        result = metaphone(str);
    }
    let endTime = Date.now();
    if (result != '') {
        throw new Error('Metaphone_Metaphone_Func_0400 error');
    }
    print(`Metaphone_Metaphone_Func_0400: ${endTime - startTime} ms`);
}

function strTestThree() {
    let result;
    const str = ' f o ';
    const startTime = Date.now();
    for (let index = 0; index < 3000000; index++) {
        result = metaphone(str);
    }
    let endTime = Date.now();
    if (result != 'F') {
        throw new Error('Metaphone_Metaphone_Func_0500 error');
    }
    print(`Metaphone_Metaphone_Func_0500: ${endTime - startTime} ms`);
}

function strTestFour() {
    let result;
    const str = '0f1o2';
    const startTime = Date.now();
    for (let index = 0; index < 3000000; index++) {
        result = metaphone(str);
    }
    let endTime = Date.now();
    if (result != 'F') {
        throw new Error('Metaphone_Metaphone_Func_0600 error');
    }
    print(`Metaphone_Metaphone_Func_0600: ${endTime - startTime} ms`);
}

function strTestFive() {
    let result;
    const str = 'Agrippa';
    const startTime = Date.now();
    for (let index = 0; index < 3000000; index++) {
        result = metaphone(str);
    }
    let endTime = Date.now();
    if (result != 'AKRP') {
        throw new Error('Metaphone_Metaphone_Func_0700 error');
    }
    print(`Metaphone_Metaphone_Func_0700: ${endTime - startTime} ms`);
}

undefinedTest();
nullTest();
strTestOne();
strTestTwo();
strTestThree();
strTestFour();
strTestFive();